package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.Validate;

import bean.InsertUpdateDelBean;
import bean.SelectBean;

public class SelectShangPinServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public SelectShangPinServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Validate vd = new Validate();
		String tem = vd.getUnicode(request.getParameter("tem"));
		String id = vd.getUnicode(request.getParameter("id"));
		String sql = "select * from shangpin where id='"+id+"'";
		String [] args = {"id","name","candi","jinjia","danjia","danwei","zhonglei","kucun","supplierid"};
		String str ="";
		SelectBean sb = new SelectBean();
		ArrayList al = sb.select(sql, args);
		request.setAttribute("dshangpin", al);
		if(tem != null && tem.equals("1")){
			str = "/shangpinlist.jsp";
		}else{
			str = "/update.jsp";
		}
		RequestDispatcher rd=request.getRequestDispatcher(str);
        rd.forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
